<template>
  <div>
    <a-modal width="300px" v-model="visible" title="设置字典编码" @ok="handleOk">
      <ZgSelect v-model="dicCode" placeholder="字典编码" :options="list"></ZgSelect>
    </a-modal>
  </div>
</template>

<script>
export default {
  data () {
    return {
      visible: false,
      tableName: '',
      columnName: '',
      dicCode: '',
      list: []
    }
  },
  mounted () {
    this.search()
  },
  methods: {
    show (col) {
      this.tableName = col.tableName
      this.columnName = col.columnName
      this.dicCode = col.dicCode
      this.visible = true
    },
    hide () {
      this.visible = false
    },
    search () {
      this.$http.get('/zg-system/dic/all', {}, data => {
        this.list = data.map(t => {
          return {
            value: t.code,
            label: t.name
          }
        })
      })
    },
    handleOk () {
      if (this.dicCode.length === 0) {
        this.$error({ title: '请设置字典编码' })
        return
      }
      this.$http.post('/zg-generator/config/column/property/set', {
        tableName: this.tableName,
        columnName: this.columnName,
        propertyName: 'dicCode',
        propertyValue: this.dicCode
      }, () => {
        this.$success({ title: '操作成功' })
        this.visible = false
      })
    }
  }
}
</script>
<style lang="less" scoped>
</style>
